home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0015 / flicker / pull.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  7KB  |  402 lines

  1. /* :ts=3 */
  2. #include "flicker.h"
  3.  
  4. extern Pull root_pull;
  5. extern char gemctable[];
  6.  
  7. WORD *draw_pull(), *save_behind();
  8.  
  9.  
  10. in_pblock(x, y, p)
  11. int x, y;
  12. register Pull *p;
  13. {
  14. if (mouse_x >= x && mouse_y >= y)
  15.     {
  16.     x += p->width;
  17.     y += p->height;
  18.     if (mouse_x <= x && mouse_y <= y)
  19.         return(1);
  20.     }
  21. return(0);
  22. }
  23.  
  24. pull_color(x, y, p)
  25. int x, y;
  26. register Pull *p;
  27. {
  28. colrop((int )p->data, x, y, p->width-1, p->height-1);
  29. }
  30.  
  31.  
  32. pull_block(x, y, p)
  33. int x, y;
  34. register Pull *p;
  35. {
  36. colrop(black, x, y, p->width-1, p->height-2);
  37. hline(y + p->height-1, x, x + p->width-1, white);
  38. }
  39.  
  40. pull_oblock(x, y, p)
  41. int x, y;
  42. register Pull *p;
  43. {
  44. int x1, y1;
  45.  
  46. colrop(black, x+1, y+1, p->width-3, p->height-3);
  47. x1 = x + p->width - 1;
  48. y1 = y + p->height - 1;
  49. hline(y, x, x1, white);
  50. hline(y1, x, x1, white);
  51. vline(x, y, y1, white);
  52. vline(x1, y, y1, white);
  53. }
  54.  
  55. pull_text(x, y, p)
  56. int x, y;
  57. register Pull *p;
  58. {
  59. extern WORD handle;
  60. v_gtext(handle, x, y+7, p->data);
  61. }
  62.  
  63. pull_brush(x, y, p)
  64. int x, y;
  65. register Pull *p;
  66. {
  67. draw_brush(brushes[(int)p->data], x+1, y+1, white);
  68. }
  69.  
  70. WORD *
  71. palloc(amount)
  72. WORD amount;
  73. {
  74. WORD *pt;
  75. amount += 2;
  76. if ((pt = alloc(amount)) == NULL)
  77.     return(NULL);
  78. *pt = amount;
  79. return (pt+1);
  80. }
  81.  
  82. pfree(pt)
  83. WORD *pt;
  84. {
  85. if (pt)
  86.     {
  87.     pt -= 1;
  88.     mfree(pt, *pt);
  89.     }
  90. }
  91.  
  92. top_print(s)
  93. char *s;
  94. {
  95. pull_block(root_pull.xoff, root_pull.yoff, &root_pull);
  96. vst_color(handle, gemctable[white]);
  97. vswr_mode(handle, 2);
  98. v_gtext(handle, 0, 7, s);
  99. }
  100.  
  101. top_line(s)
  102. char *s;
  103. {
  104. WORD *abehind;
  105.  
  106. unzoom();
  107. hide_mouse();
  108. if ((abehind = save_behind(root_pull.xoff, root_pull.yoff, &root_pull)) == NULL)
  109.     return;    /* out of memory dudes */
  110. top_print(s);
  111. wait_a_jiffy(20);    /* 1/3 second before mouse move makes it go away */
  112. show_mouse();
  113. for (;;)
  114.     {
  115.     check_input();
  116.     if (mouse_moved)
  117.         break;
  118.     if (key_hit)
  119.         {
  120.         reuse_input();
  121.         break;
  122.         }
  123.     }
  124. undraw_pull(root_pull.xoff, root_pull.yoff, &root_pull, abehind);
  125. rezoom();
  126. }
  127.  
  128. /* reset things some so can draw on physical screen in spite of zoom */
  129. unzoom()
  130. {
  131. if (zoom_flag)    /* do some re-arranging so pulldowns are in our screen */
  132.     {
  133.     hide_mouse();
  134.     zbuf_to_screen();
  135.     draw_on_screen();
  136.     show_mouse();
  137.     zscale_cursor = 0;
  138.     }
  139. }
  140.  
  141. rezoom()
  142. {
  143. if (zoom_flag)    /* put things back for zoom maybe */
  144.     {
  145.     zscale_cursor = 1;
  146.     hide_mouse();
  147.     draw_on_buffer();
  148.     show_mouse();
  149.     }
  150. }
  151.  
  152. init_menu_colors()
  153. {
  154. find_colors();
  155. vst_color(handle, gemctable[white]);
  156. vswr_mode(handle, 2);
  157. }
  158.  
  159.  
  160. pull(p)
  161. Pull *p;
  162. {
  163. WORD *abehind, *bbehind = NULL, *cbehind = NULL; /*buffers for
  164.                                                 menu-bar, drop-down, and
  165.                                                 hilit selection */
  166. WORD cline_size, cbehind_size;  /* dimensions of hilight box in bytes */
  167. WORD x, y;  /* root offset */
  168. WORD cx, cy; /* offset of "menu" level lettering aka amiga terminology */
  169. WORD ccx, ccy; /* offset of drop downs */
  170. WORD sx, sy;    /* offset of selection */
  171. WORD i, j;
  172. WORD menu_down = -1;
  173. WORD sel_hi = -1;
  174. Pull *child;
  175. Pull *cchild = NULL;
  176. Pull *select = NULL;    
  177. Pull *scratch;
  178. WORD scx, scy;    /* scratch (selection) offset */
  179. WORD pulled = -1;    /* the result */
  180.  
  181. if (!RDN)
  182.     return(-1);
  183. unzoom();
  184. init_menu_colors();
  185. x = p->xoff;
  186. y = p->yoff;
  187. if ((abehind = draw_pull(x, y, p)) == NULL)
  188.     {
  189.     pulled = -1;
  190.     goto outta_pull;    /* out of memory dudes */
  191.     }
  192. for (;;)
  193.     {
  194.     check_input();
  195.     if (key_hit)
  196.         {
  197.         reuse_input();
  198.         break;
  199.         }
  200.     else if (RJSTDN)
  201.         {
  202.         wait_rup();
  203.         break;
  204.         }
  205.     else
  206.         {
  207.         child = p->children;
  208.         i = 0;
  209.         while (child)
  210.             {
  211.             cx = x + child->xoff;
  212.             cy = y + child->yoff;
  213.             if (in_pblock(cx, cy, child))
  214.                 {
  215.                 if (menu_down != i)
  216.                     {
  217.                     if (select)
  218.                         {
  219.                         undraw_pull(sx, sy, select, cbehind);
  220.                         select = NULL;
  221.                         sel_hi = -1;
  222.                         }
  223.                     if (cchild)
  224.                         {
  225.                         undraw_pull(ccx, ccy,  cchild, bbehind);
  226.                         }
  227.                     if ((cchild = child->children) != NULL)
  228.                         {
  229.                         ccx = cx + cchild->xoff;
  230.                         ccy = cy + cchild->yoff;
  231.                         if ((bbehind =  draw_pull(ccx, ccy, cchild) ) == NULL)
  232.                             {
  233.                             goto outta_pull;
  234.                             }
  235.                         }
  236.                     menu_down = i;
  237.                     }
  238.                 break;
  239.                 }
  240. next_child:
  241.             child = child->next;
  242.             i++;
  243.             }
  244.         if (cchild  != NULL)
  245.             {
  246.             if (in_pblock(ccx, ccy, cchild))
  247.                 {
  248.                 scratch = cchild->children;
  249.                 j = 0;
  250.                 while (scratch)
  251.                     {
  252.                     scx = ccx + scratch->xoff;
  253.                     scy = ccy + scratch->yoff;
  254.                     if (in_pblock(scx, scy, scratch))
  255.                         {
  256.                         if (sel_hi != j)
  257.                             {
  258.                             if (select)
  259.                                 {
  260.                                 undraw_pull(sx, sy, select, cbehind);
  261.                                 }
  262.                             select = scratch;
  263.                             sx = scx;
  264.                             sy = scy;
  265.                             sel_hi = j;
  266.                             cline_size = cbehind_size = Raster_line(scratch->width);
  267.                             cbehind_size *= scratch->height;
  268.                             if ( (cbehind = palloc(cbehind_size) ) == NULL)
  269.                                 {
  270.                                 goto outta_pul;
  271.                                 }
  272.                             hide_mouse();
  273.                             copy_blit(scratch->width, scratch->height, scx, scy, 
  274.                                cscreen,  160, 
  275.                                 0, 0, cbehind, cline_size);
  276.                             draw_frame(red, scx, scy, scx+scratch->width-1,
  277.                                 scy+scratch->height-1);
  278.                             show_mouse();
  279.                             }
  280.                         goto maybe_pulled;
  281.                         }
  282.                     scratch = scratch->next;
  283.                     j++;
  284.                     }
  285.                 }
  286.             }
  287.         }
  288. maybe_pulled:
  289.     if (PDN)
  290.         {
  291.         if (select != NULL)
  292.             {
  293.             if (in_pblock(sx, sy, select))
  294.                 {
  295.                 pulled = (menu_down<<8)+sel_hi;
  296.                 }
  297.             }
  298.         wait_penup();
  299.         break;
  300.         }
  301.     }
  302. if (select)
  303.     {
  304.     undraw_pull(sx, sy, select, cbehind);
  305.     }
  306. outta_pul:
  307. if (cchild)
  308.     {
  309.     undraw_pull(ccx, ccy, cchild, bbehind);
  310.     }
  311. outta_pull:
  312. undraw_pull(x, y, p, abehind);
  313. rezoom();
  314. return(pulled);
  315. }
  316.  
  317. undraw_pull(x, y, p, abehind)
  318. register int x, y;
  319. register Pull *p;
  320. WORD *abehind;
  321. {
  322. WORD abehind_size;
  323. WORD aline_size;
  324.  
  325. aline_size = abehind_size = Raster_line(p->width);
  326. abehind_size *= p->height;
  327. hide_mouse();
  328. copy_blit(p->width, p->height, 0, 0, abehind, aline_size,
  329.     x, y, cscreen, 160);
  330. show_mouse();
  331. pfree(abehind);
  332. }
  333.  
  334. WORD *
  335. save_behind(x, y, p)
  336. register int x, y;
  337. register Pull *p;
  338. {
  339. WORD *abehind;
  340. WORD abehind_size;
  341. WORD aline_size;
  342.  
  343. aline_size = abehind_size = Raster_line(p->width);
  344. abehind_size *= p->height;
  345. if ( (abehind = palloc(abehind_size) ) == NULL)
  346.     return(NULL);    /* not enough memory */
  347. copy_blit(p->width, p->height, x, y, cscreen,  160, 
  348.     0, 0, abehind, aline_size);
  349. return(abehind);
  350. }
  351.  
  352.  
  353. WORD *
  354. draw_pull(x, y, p)
  355. register int x, y;
  356. register Pull *p;
  357. {
  358. WORD *abehind;
  359.  
  360. hide_mouse();
  361. if ((abehind = save_behind(x, y, p)) == NULL)
  362.     return(NULL);    /* not enough memory */
  363. (*p->see)(x, y, p);
  364. p = p->children;
  365. while (p)
  366.     {
  367.     (*p->see)(x + p->xoff, y+p->yoff, p);
  368.     p = p->next;
  369.     }
  370. show_mouse();
  371. return(abehind);
  372. }
  373.  
  374. unxmenu(p)
  375. register Pull *p;
  376. {
  377. while (p)
  378.     {
  379.     p->data[0] = ' ';
  380.     p = p->next;
  381.     }
  382. }
  383.  
  384. xone(p, one)
  385. register Pull *p;
  386. register int one;
  387. {
  388. while (--one >= 0)
  389.     p = p->next;
  390. p->data[0] = 'x';
  391. }
  392.  
  393. xonflag(p, flag)
  394. register Pull *p;
  395. WORD flag;
  396. {
  397. if (flag)
  398.     p->data[0] = 'x';
  399. else
  400.     p->data[0] = ' ';
  401. }
  402.